package ee.videorentalstore.protocols.types;

import java.util.ArrayList;

import ee.videorentalstore.UserAndProtocolManager;
import ee.videorentalstore.UserAndProtocolManagerStatus;
import ee.videorentalstore.protocols.Protocol;
import ee.videorentalstore.protocols.commands.Command;
import ee.videorentalstore.protocols.commands.ExitSystemCommand;
import ee.videorentalstore.protocols.commands.GiveCurrentProtocolInformationCommand;
import ee.videorentalstore.protocols.commands.WhoIsInControlCommand;
import ee.videorentalstore.protocols.commands.changingsystemusercommands.GetHelpWhileChangingSystemUserCommand;
import ee.videorentalstore.protocols.commands.changingsystemusercommands.GetListOfAllCustomersCommand;
import ee.videorentalstore.protocols.commands.changingsystemusercommands.GetListOfAllUsersCommand;
import ee.videorentalstore.protocols.commands.changingsystemusercommands.SetSystemUserByUserIdCommand;
import ee.videorentalstore.utils.UserInputReader;

public class ChanginSystemUserProtocol extends Protocol
{
	private ArrayList<Command> changingSystemUserProtocolCommandList = new ArrayList<Command>();
	private final String COMMAND_DESCRIPTION_AND_ITS_CONTENTS_SPLITTING_CONSTANT = "----";
	
	
	public ChanginSystemUserProtocol()
	{
		changingSystemUserProtocolCommandList.add(new GetHelpWhileChangingSystemUserCommand());
		changingSystemUserProtocolCommandList.add(new GetListOfAllCustomersCommand());
		changingSystemUserProtocolCommandList.add(new GetListOfAllUsersCommand());
		changingSystemUserProtocolCommandList.add(new SetSystemUserByUserIdCommand());
		changingSystemUserProtocolCommandList.add(new WhoIsInControlCommand());
		changingSystemUserProtocolCommandList.add(new ExitSystemCommand());
		changingSystemUserProtocolCommandList.add(new GiveCurrentProtocolInformationCommand());
	}
	
	
	@Override
	public void runUserProtocol() 
	{
		while (UserAndProtocolManager.getInstance().getUserAndProtocolManagerStatus() 
				== UserAndProtocolManagerStatus.CHANGING_USER_AND_PROTOCOL)
		{
			String instructionsInsertedByUserToProcess = UserInputReader.getInstance().readLine();
			
			if (!instructionsInsertedByUserToProcess.contains(COMMAND_DESCRIPTION_AND_ITS_CONTENTS_SPLITTING_CONSTANT))
			{
				instructionsInsertedByUserToProcess += COMMAND_DESCRIPTION_AND_ITS_CONTENTS_SPLITTING_CONSTANT;
			}
			
			parseCommandFromInstructionsAndExecute(instructionsInsertedByUserToProcess, changingSystemUserProtocolCommandList);
		}
	}
}
